package com.pmsystem.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pmsystem.pojo.GasConsume;
import com.pmsystem.service.GasConsumeService;
import com.pmsystem.util.BeanUtil;

@Controller
public class GasConsumeController {

	@Autowired
	private GasConsumeService gasConsumeService;
	
	/**
	 * 
	 * <p>Title: addGasConsume</p >  
	 * <p>Description: 录入燃气费</p >  
	 * @author 泽强
	 * @param gasConsume
	 * @return
	 */
	@RequestMapping(value="addGasConsume",method=RequestMethod.POST)
	@ResponseBody
	public Object addGasConsume(@RequestParam Map<String,Object> map) {
		GasConsume gasConsume = BeanUtil.parserToBean(BeanUtil.mapToMapWithoutNull(map),GasConsume.class);
		boolean flag = gasConsumeService.addGasConsume(gasConsume);
		if(flag) {
			return "success";
		}
		return "error";
	}
	
	/**
	 * 
	 * <p>Title: updateGasConsume</p >  
	 * <p>Description: 修改燃气信息</p >  
	 * @author 泽强
	 * @param gasConsume
	 * @return
	 */
	@RequestMapping(value="updateGasConsume",method=RequestMethod.POST)
	@ResponseBody
	public Object updateGasConsume(@RequestParam Map<String,Object> map) {
		GasConsume gasConsume = BeanUtil.parserToBean(BeanUtil.mapToMapWithoutNull(map),GasConsume.class);
		boolean flag = gasConsumeService.updateGasConsume(gasConsume);
		if(flag) {
			return "success";
		}
		return "error";
	}
	
	@RequestMapping(value="findGasConsume",method=RequestMethod.GET)
	@ResponseBody
	public Object findGasConsume(@RequestParam Map<String,Object> map) {
		List<GasConsume> list = gasConsumeService.findGasConsume(map);
		return list;
	}
}
